package com.nanyang.tms.service.waybill.impl.flow;

import com.nanyang.common.core.domain.ApiRequest;
import com.nanyang.common.core.flow.context.TransHandlerContext;
import com.nanyang.common.core.flow.convert.TransConvert;
import com.nanyang.common.tool.utils.convert.BeanUtils;
import com.nanyang.tms.api.dto.request.waybill.WaybillAddReuqest;
import com.nanyang.tms.domain.forecast.context.CalculateWeightVolumeContext;
import com.nanyang.tms.domain.waybill.context.WaybillAddContext;

public class WaybillConvert implements TransConvert{

	@Override
	public TransHandlerContext convertRequest2Ctx(ApiRequest req, TransHandlerContext context) {
		WaybillAddReuqest waybillAddReuqest=(WaybillAddReuqest)req;
		WaybillAddContext waybillAddContext=(WaybillAddContext) context;
		//设置重量计算参数
		BeanUtils.copyProperties(waybillAddReuqest, waybillAddContext.getCalculateWeightContext());
		waybillAddContext.getCalculateWeightContext().setCityCode(waybillAddReuqest.getProvinceCode());
		BeanUtils.copyListProperties(waybillAddReuqest.getVolumes(), waybillAddContext.getCalculateWeightContext().getCalculateWeightVolumeContexts(), CalculateWeightVolumeContext.class);
		//设置运费计算参数
		BeanUtils.copyProperties(waybillAddReuqest, waybillAddContext.getCalculateFreightContext());
		//设置保存运单参数
		BeanUtils.copyProperties(waybillAddReuqest, waybillAddContext.getSaveWaybillReceiptContext());
		
		return waybillAddContext;
	}

}
